import svc
import uthread

class EveActionObjectClientSvc(svc.actionObjectClientSvc):
    __guid__ = 'svc.eveActionObjectServerSvc'
    __replaceservice__ = 'actionObjectClientSvc'

    def PrepareComponent(self, sceneID, entityID, component):
        if ('actionObjectUID' in self.preservedStates[component]):
            actionObjID = self.preservedStates[component].get('actionObjectUID', None)
        elif ('graphicID' in self.preservedStates[component]):
            graphicID = self.preservedStates[component]['graphicID']
        else:
            graphicID = cfg.invtypes.Get(self.preservedStates[component]['_typeID']).Graphic().id
        actionObjID = (cfg.graphics.Get(graphicID).animationTemplate if (graphicID in cfg.graphics) else None)
        self._PrepareComponent(entityID, component, actionObjID)



    def SetupComponent(self, entity, component):
        infoComponent = entity.GetComponent('info')
        if (infoComponent and (not infoComponent.name)):
            typeData = cfg.invtypes.Get(self.preservedStates[component]['_typeID'])
            infoComponent.name = typeData.name
        svc.actionObjectClientSvc.SetupComponent(self, entity, component)



    def _PerformUICallback(self, callbackKey):
        uthread.worker('_PerformUICallback', self._PerformUICallbackTasklet, callbackKey)
        return True



    def _PerformUICallbackTasklet(self, callbackKey):
        if (callbackKey is None):
            self.LogError('PerformUICallback called from ActionObject without the callbackKey property!')
        elif (callbackKey == 'OpenCharacterCustomization'):
            uicore.cmd.OpenCharacterCustomization()
        elif (callbackKey == 'CorpRecruitment'):
            uicore.cmd.OpenCorporationPanel_RecruitmentPane()
        elif (callbackKey == 'OpenCorporationPanel_Planets'):
            uicore.cmd.OpenCorporationPanel_Planets()
        elif (callbackKey == 'OpenAuraInteraction'):
            uicore.cmd.OpenAuraInteraction()
        elif (callbackKey == 'ExitStation'):
            uicore.cmd.CmdExitStation()
        elif (callbackKey == 'OpenFitting'):
            uicore.cmd.OpenFitting()
        elif (callbackKey == 'OpenShipHangar'):
            uicore.cmd.OpenShipHangar()
        elif (callbackKey == 'OpenMarket'):
            uicore.cmd.OpenMarket()
        else:
            self.LogError('ActionObject.PerformUICallback: Unknown callbackKey', callbackKey)




